﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ConfigurationServer.AppCode.Filters
{

    // http://stackoverflow.com/questions/11353155/measure-time-invoking-mvc-4-controller-actions
    public class PerformanceTestFilter : ActionFilterAttribute
    {
        private Stopwatch stopWatch = new Stopwatch();

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            stopWatch.Reset();
            stopWatch.Start();
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            stopWatch.Stop();
            var executionTime = stopWatch.ElapsedMilliseconds;
            string strAction = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + filterContext.ActionDescriptor.ActionName;
            //Task.Run(() => registerHitTest(data.key, data.set));
            //CFiltroLogging.registroLog(strAction + "-" + string.Format("{0:###.00}", executionTime), CInfoNavegacion.Usuario.Email);
        }
    }
}